<?php

namespace core\traits;

use support\Response as SupportResponse;
use support\View;

trait AdminView
{

    public function view(
        array $var = [],
        bool $frame = true,
        string $template = ''
    ): SupportResponse {

        if ($template != '') {
            View::assign('template', $template);
        } else {
            $controller = get_controller();
            if (is_plugin()) {
                View::assign('template',   base_path() . '/template/admin/' . get_plugin() . '/' . mb_substr(get_controller(), 6) . '/' . request()->action . '.php');
            } else {
                View::assign('template',   base_path() . '/template/admin/frame/' . mb_substr($controller, 6) . '/' . request()->action . '.php');
            }
        }
      
        if ($frame) {
       
            return raw_view('/template/admin/layout', $var, '', '');
        }
        return raw_view('/template/admin/noframelayout', $var, '', '');
    }
}
